/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.palandrodev.calsmart.base;

/**
 * 
 * @author palaniappan
 */
public class Tip {

	private float bill_amount;
	private float percentage;
	private int divided_between;

	private float tip_amount;
	private float total_amount;
	private float individual_share;

	public float getBillAmount() {
		return bill_amount;
	}

	public void setBillAmount(float amount) {
		this.bill_amount = amount;
	}

	public float getPercentage() {
		return percentage;
	}

	public void setPercentage(float percentage) {
		this.percentage = percentage;
	}

	public int getDivided_between() {
		return divided_between;
	}

	public void setDivided_between(int divided_between) {
		this.divided_between = divided_between;
	}

	public float getTip_amount() {
		return tip_amount;
	}

	public void setTip_amount(float tip_amount) {
		this.tip_amount = tip_amount;
	}

	public float getIndividual_share() {
		return individual_share;
	}

	public void setIndividual_share(float individual_share) {
		this.individual_share = individual_share;
	}

	public float getTotal_amount() {
		return total_amount;
	}

	public void setTotal_amount(float total_amount) {
		this.total_amount = total_amount;
	}

	public Tip(float amount, float percentage, int divided_between) {
		this.bill_amount = amount;
		this.percentage = percentage;
		this.divided_between = divided_between;
	}

	public Tip() {
		this.bill_amount = 0.0f;
		this.percentage = 0.0f;
		this.divided_between = 0;
	}

	@Override
	public String toString() {
		if (isEmpty()) {
			return "";
		} else {
			return "Tip{" + "amount=" + bill_amount + ", percentage="
					+ percentage + ", divided_between=" + divided_between + '}';
		}
	}

	@Override
	public int hashCode() {
		if (this.isEmpty()) {
			return 0;
		} else {
			int hash = 3;
			hash = 37 * hash + Float.floatToIntBits(this.bill_amount);
			hash = 37 * hash + Float.floatToIntBits(this.percentage);
			hash = 37 * hash + this.divided_between;
			return hash;
		}

	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final Tip other = (Tip) obj;
		if (Float.floatToIntBits(this.bill_amount) != Float
				.floatToIntBits(other.bill_amount)) {
			return false;
		}
		if (Float.floatToIntBits(this.percentage) != Float
				.floatToIntBits(other.percentage)) {
			return false;
		}
		if (this.divided_between != other.divided_between) {
			return false;
		}
		return true;
	}

	public boolean isEmpty() {
		if (this.bill_amount == 0.0f && this.percentage == 0.0f
				&& this.divided_between == 0) {
			return true;
		} else {
			return false;
		}
	}

	public void calculate() {
		this.setTip_amount((this.bill_amount * (this.percentage / 100.00f)));
		this.setTotal_amount(this.bill_amount + this.getTip_amount());

		if (this.divided_between > 0) {
			this.setIndividual_share(((this.getTotal_amount()) / this.divided_between));
		} else {
			this.setIndividual_share(this.getTotal_amount());
		}

	}
}
